<?php

/**
 * Class AccountController
 */
class AdminController extends BaseController
{


    /**
     * 获取体验金
     * @return mixed
     */
    public function GetCash()
    {
//        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
//        $info = AdminService::instance()->GetCash($user_id);
        $invite_mobile= $this->getParam('invite_mobile');
        if(!empty($invite_mobile)){
            return $this->view('index.invite_receive')->with('invite_mobile',$invite_mobile);
        }

    }

    /**
     * 手机号验证
     * @return int
     */
    public function CheckMobile()
    {
        #接收参数
        $paramObj                       =          new stdClass();
        $paramObj->mobile               =          $this->getParam('mobile');               //手机号

        $rs = AdminService::instance()->CheckMobile($paramObj);
        if(!$rs){
            return 0;
        }

    }

    /**
     * 邀请注册
     * @return mixed
     */
    public function Register()
    {
        if(Request::isMethod('post')){
            #收集信息
            $paramObj = new stdClass();
            $paramObj->mobile                =       $this->getParam('mobile');
            $paramObj->invite_mobile         =       $this->getParam('invite_mobile');

            Session::put('mobile',$paramObj->mobile);
            Session::put('invite_mobile',$paramObj->invite_mobile);

        }

        $mobile = Session::get('mobile');
        $invite_mobile = Session::get('invite_mobile');
        if(!empty($mobile)){
            return $this->view('index.invite_register')->with(['mobile'=> $mobile,'invite_mobile'=>$invite_mobile]);

        }

    }

    /**
     * 发送短信验证码
     * @return string
     */
    public function VerifyNews()
    {
        if(Request::isMethod('POST')){
            #接收参数
            $paramObj = new stdClass();
            $paramObj->mobile            =       $this->getParam('mobile');                  //联系方式


            if(!empty($paramObj->mobile))
            {
                $data = AdminService::instance()->VerifyNews($paramObj);
                return $data;
            }
        }
    }

    /**
     * 短信验证
     * @return int
     */
    public function CheckNews()
    {
        if (Request::isMethod('POST')) {
            #接收参数
            $paramObj = new stdClass();
            $paramObj->mobile           =   $this->getParam('mobile');                   //电话
            $paramObj->news_captcha     =   $this->getParam('news_captcha');             //短信验证码


            if (!empty($paramObj->news_captcha)) {
                $data = AdminService::instance()->CheckNews($paramObj);
                return $data;
            }
        }
    }

    public function VerifyRegister()
    {
        if (Request::isMethod('POST')) {
            #接收参数
            $paramObj = new stdClass();
            $paramObj->pwd                =       $this->getParam('pwd');                       //密码
            $paramObj->mobile             =       $this->getParam('mobile');                    //联系方式
            $paramObj->news_captcha       =       $this->getParam('news_captcha');              //短信验证码
            $paramObj->invite_mobile      =       $this->getParam('invite_mobile');              //邀请人联系方式


            #逻辑处理
            try{
                AdminService::instance()->VerifyRegister($paramObj);
                return Redirect::to('/invite_download');
            }catch(Exception $e){
                print_R($e->getMessage());
                //$this->rest->error($e->getMessage(), $e->getCode());
            }
        }
    }

    /**
     * 客户端下载
     * @return mixed
     */
    public function InviteDownload()
    {
        return $this->view('index.invite_download');
    }

    /**
     * 客户端下载
     * @return mixed
     */
    public function Download()
    {
        return $this->view('index.download');
    }

}





